package com.ieheima.zuoye6;

import java.util.*;

public class Test {
    public static void main(String[] args) {


        ArrayList<Person> persons = new ArrayList<>();
        persons.add(new Person("张成", 28, "甘肃"));
        persons.add(new Person("刘安", 37, "宁夏"));
        persons.add(new Person("刘墉", 40, "山东"));
        persons.add(new Person("和坤", 35, "北京"));
        persons.add(new Person("和二", 36, "北京"));
        persons.add(new Person("纪晓岚", 39, "山西"));
        persons.add(new Person("刘安", 37, "宁夏"));
        //随机打印一组人员信息


        persons.stream().skip(new Random().nextInt(persons.size())).findFirst().ifPresent(System.out::println);
        //删除集合中和性的人员
        for (int i = 0; i < persons.size(); i++) {
            if (persons.get(i).getName().contains("和")){
                persons.remove(i);
                i--;
            }
        }
        System.out.println("删除集合中的和性人员成功");
        persons.forEach(System.out::println);
        System.out.println("===========");

        //删除重复的人员信息
        Set<Person> set = new HashSet<>();
        for (Person person : persons) {
            set.add(person);
        }
        set.forEach(System.out::println);

        System.out.println("===========");
       set.stream().filter(person -> person.getAge() > 35).forEach(System.out::println);



    }



}
